import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class Test {
    @ParameterizedTest
    @CsvFileSource(resources = "superadminLogin.csv")
    void login(String name,String password,String loginURL,String toURL) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        //获取登录页
        webDriver.get(loginURL);
        webDriver.manage().window().maximize();
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        System.out.println("username:" + name);
        System.out.println("password:" + password);
        //输入账号密码
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(1) > div > div > input")).sendKeys(name);
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(2) > div > div > input")).sendKeys(password);
        //点击登录
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(3) > div > button")).click();
        webDriver.manage().window().maximize();
        sleep(3000);

        String curUrl = webDriver.getCurrentUrl();
        Assertions.assertEquals(toURL, curUrl);
        sleep(3000);

        //获取 页面所有的机构名元素 验证是否删除成功
        List<WebElement> colleges = webDriver.findElements(By.cssSelector("h1 > font"));
        //#el-collapse-head-3562 > h1 > font
        System.out.println(colleges.size());
        for (int i = 0; i < colleges.size(); i++) {
            System.out.println(colleges.get(i).getText());
        }
//        System.out.println(colleges.get(1).getText());
//        colleges.get(1).click();
        sleep(3000);
    }
    public static void main(String[] args) {
        int randomNumber = (int)(Math.random() * 100) + 1;
        System.out.println("生成的随机数是： " + randomNumber);
    }
}
